package com.timebank.websocket.factory;

import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.websocket.pojo.vo.SendMsgVO;
import com.timebank.websocket.service.RemoteWebSocketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * websocket 服务降级处理
 * @author shiliuyinzhen
 */
@Component
public class RemoteWebSocketFallBackFactory implements FallbackFactory<RemoteWebSocketService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteWebSocketFallBackFactory.class);

    @Override
    public RemoteWebSocketService create(Throwable throwable) {
        log.error("WebSocket服务调用失败:{}", throwable.getMessage());
        return new RemoteWebSocketService(){
            @Override
            public AjaxResult sendMessage(SendMsgVO sendMsgVO, String source) {
                return AjaxResult.error("发送消息调用失败：{}" + throwable.getMessage());
            }

        };
    }
}
